-
Notifications
You must be signed in to change notification settings - Fork 123
rewrite client to use ServiceTemplate based API #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hello @niemannd! |
Hi @niemannd !
even if we can let the possibility to customize it if we want.
Again thanks a lot for what you propose and your work. I understand your purpose not to have one uber class and create more accessibility. Still, this SDK is small and only contains few methods to bring too much complexity for the primary usage it offers. |
There are a few reasons i chose to not do that.
I chose not to do that because this creates a number of problems.
|
Hi @niemannd, |
Honestly i don't see the developer-unfriendly part. Do you mean the Index class? A similar pattern is used in the meilisearch-go sdk. Do you mean the ClientBuilder? Again, a similar pattern is used by meilisearch-go and even Spring Data Elasticsearch So please help me to understand whats the problem with changing the example in the readme of an SDK thats barely used at the moment. If there is a time to change it, its before the sdk is integrated into hundreds of backends. |
Hi @niemannd,
We actually do a refactor of the go SDK for the same reason. It is noted that it’s wasn’t clear for the user to pass the name of the index in the function like: |
❌⚠️ This PR is a major breaking change! ⚠️ ❌
This is a rewrite of the Client and Config classes.
I added a modelMapping to the Config class. This way we are able to specify which index should be mapped to what Java Class.
The Client class now has accessors for the specific apis.
client.index()
returns the IndexHandler,client.documents("indexname")
returns the DocumentHandler for the specified index.client.documents("indexname", Movie.class)
returns a DocumentHandler for the specified index withMovie
as the desired Java Type, even if there is no mapping in the config for it.client.instance()
returns the InstanceHandlerclient.keys()
returns the KeysHandlerThis way we dont have one uber-class that implements everything.
To make this easier, i created a ClientBuilder class. It allows the user to set every part of the ServiceTemplate classes (HttpClient, JsonHandler, RequestFactory, ServiceTempalte). If nothing gets specified, the ClientBuilder autodetects classes in the Classpath and loads the apropriate Implementation.